<?php
namespace app\user\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\user\model\Service_supply;
use app\user\model\Unit;
use app\user\model\Service_purchase;
use app\user\model\User_shop;
class Procurement extends Controller
{
	//采购大厅展示页面
    public function index(Service_purchase $Service_purchase)
    {
        $info = $Service_purchase->getorder();
        $this->assign('info',$info);
        return $this->fetch();
    }
    //新增采购大厅
    public function add(Unit $Unit,Service_supply $Service_supply,User_shop $User_shop)
    {
      	$list = $Unit->getlist();
        $info = $User_shop->orderinfo();
        $this->assign('info',$info);
      	$this->assign('list',$list);
        return $this->fetch();
    }
    public function addinfo(Service_purchase $Service_purchase)
    {
       $info = input();

       $list = $Service_purchase->create($info);
       if ($list){
           return 1;
       }else{
           return 2;
       }
  
    }
    //删除产品
    public function delpro(Service_purchase $Service_purchase)
    {

       $id = input('id');
       $res = $Service_purchase->destroy($id);
       if ($res) {
          return json(1);
       }else{
          return json(2);
       }


    }

    //信息编辑页面
    public function edit(Service_purchase $Service_purchase,Unit $Unit)
    {
      $id = input('id');
      $list = $Unit->getlist();
      $info = $Service_purchase->where('ID',$id)->find();
      $this->assign('list',$list);
      $this->assign('info',$info);
      return $this->fetch();
    }
    //修改数据
    public function pro_update(Service_purchase $Service_purchase)
    {
      $info = input();
      $infolist = $Service_purchase->where('ID',$info['infoid'])->update($info);
      if ($infolist) {
        return json(1);
      }else{
        return json(2);
      }

    }


}
